package com.sw.bbs.board.controller;

import com.github.pagehelper.PageInfo;
import com.sw.bbs.common.common.GlobalException;
import com.sw.bbs.board.service.ProfileService;
import com.sw.bbs.board.vo.request.QueryCommonRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @Desc: No Desc
 * @Author: wusonghe
 * @Date: 2019/3/5 17:18
 */
@Api(value = "用户信息模块", description = "用户信息", tags = {"Profile Module"})
@RestController("/profile/")
public class ProfileController {

    private static final Logger logger = LoggerFactory.getLogger(ProfileController.class);

    @Autowired
    private ProfileService profileService;


    @GetMapping("/boardList")
    @ApiOperation(value = "用户的板块接口", notes = "用户的板块", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> boardList(QueryCommonRequest queryCommonRequest, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            PageInfo result = profileService.boardList(queryCommonRequest, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            logger.error("boardList", e);
            throw new GlobalException("/profile/boardList", e.getMessage());
        }
    }

    @GetMapping("/boardFollowList")
    @ApiOperation(value = "用户关注的板块接口", notes = "用户关注的板块", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> boardLikeList(QueryCommonRequest queryCommonRequest, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            PageInfo result = profileService.boardCollectList(queryCommonRequest, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            logger.error("boardFollowList", e);
            throw new GlobalException("/profile/boardCollectList", e.getMessage());
        }
    }

    @GetMapping("/postList")
    @ApiOperation(value = "用户的帖子接口", notes = "用户的帖子", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> postList(QueryCommonRequest queryCommonRequest, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            PageInfo result = profileService.postList(queryCommonRequest, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            logger.error("postList", e);
            throw new GlobalException("/profile/postList", e.getMessage());
        }
    }

    @GetMapping("/postFollowList")
    @ApiOperation(value = "用户关注的帖子接口", notes = "用户关注的帖子", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> postLikeList(QueryCommonRequest queryCommonRequest, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            PageInfo result = profileService.postFollowList(queryCommonRequest, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            logger.error("postCollectList", e);
            throw new GlobalException("/profile/postCollectList", e.getMessage());
        }
    }

    @GetMapping("/postCollectList")
    @ApiOperation(value = "用户收藏的帖子接口", notes = "用户关注的帖子", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> postCollectList(QueryCommonRequest queryCommonRequest, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            PageInfo result = profileService.postCollectList(queryCommonRequest, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            logger.error("postCollectList", e);
            throw new GlobalException("/profile/postCollectList", e.getMessage());
        }
    }

    @GetMapping("/commentList")
    @ApiOperation(value = "用户评论列表接口", notes = "用户评论列表", response = ResponseEntity.class)
    @ApiResponses({@ApiResponse(code = 200, message = "分页结果结构", response = ResponseEntity.class)})
    public ResponseEntity<?> commentList(QueryCommonRequest queryCommonRequest, HttpServletRequest httpServletRequest)
            throws GlobalException {
        try {
            PageInfo result = profileService.commentList(queryCommonRequest, httpServletRequest);
            return new ResponseEntity<>(result, HttpStatus.OK);
        } catch (Exception e) {
            logger.error("commentList", e);
            throw new GlobalException("/profile/commentList", e.getMessage());
        }
    }

    

}
